﻿namespace FFF.Test
{
    using System;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using Abp.Application.Services;
    using Abp.AspNetCore.Runtime.Cache;
    using Microsoft.AspNetCore.Authentication.JwtBearer;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.IdentityModel.Tokens;
    using FFF.Test.Filters;
    using FFF.Test.Framework.IM;
    using FFF.Test.Util.Consts;
    using FFF.Test.Util.Web;
    using Swashbuckle.AspNetCore.Swagger;
    using Swashbuckle.AspNetCore.SwaggerGen;
    using Swashbuckle.AspNetCore.SwaggerUI;
    using Ydm.LayIM.AspNetCore.Core;

    /// <summary>
    /// 配置IM
    /// </summary>
    public static class IMConfigurer
    {
        /// <summary>
        /// 配置IM依赖注入
        /// </summary>
        /// <param name="services">程序的服务对象</param>
        /// <param name="configuration">程序的配置对象</param>
        /// <param name="env">环境节点</param>
        public static void ConfigureServices(IServiceCollection services, IConfiguration configuration, IHostingEnvironment env)
        {
            //注册LayIM的默认服务
            services.AddLayIM(() =>
            {
                return new IMUserFactory();
            }).AddSignalR(options =>
            {
                options.HubConfigure = hubOptions =>
                {
                    hubOptions.EnableDetailedErrors = true;
                    hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(5);
                };
            })
                .AddSqlServer(AppConfigConsts.ConStr);
        }

        /// <summary>
        /// 配置IM请求处理
        /// </summary>
        /// <param name="app">app环境</param>
        /// <param name="env">env的环境</param>
        public static void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            //使用LayIM，自定义配置
            app.UseLayIM(options =>
            {
                options.ServerType = ServerType.SignalR;
                options.UIConfig.UseMessageBoxPage = true;
            });
        }
    }
}
